package com.ipt.frm.pw;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ipartek.fila2.bean.Alumno;
import com.ipartek.fila2.factoria.DAOFactory;
import com.ipartek.fila2.interfaces.InterfaceAlumnoDAO;
import com.ipartek.fila2.interfaces.InterfaceTiradaDAO;

/**
 * Servlet implementation class servletRanking
 */
public class servletRanking extends ServletMaestro {

	private static final long serialVersionUID = -5186174395080599897L;

	private static DAOFactory fMySql;
	private static InterfaceAlumnoDAO aDao;
	private static InterfaceTiradaDAO tDao;
	private static final String TABLE_ALUMNO = "alumno";
	private static final String TABLE_TIRADA = "tirada";

	protected void processRequest(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		ArrayList<Alumno> Alumnos = new ArrayList<Alumno>();
		ArrayList listaAlumnos = new ArrayList();
		Alumno alumno;
		String nombre;
		int tiradaInt;
		String fecha = "";
		try {
			fMySql = DAOFactory.getDAOFactory(DAOFactory.MYSQL);
			aDao = fMySql.getInterfaceAlumnoDAO();
			Alumnos = aDao.getAlumnosActivos(TABLE_ALUMNO);

		} catch (Exception e) {
			e.printStackTrace();
		}

		request.setAttribute("alumnos", Alumnos);
		request.setAttribute("title", "Ranking tiradas");
		RequestDispatcher dispacher = this.getServletContext()
				.getRequestDispatcher("/ranking.jsp");
		dispacher.forward(request, response);
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	@Override
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		processRequest(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	@Override
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		processRequest(request, response);
	}

}
